let util = require('util');
let mysqlPool = require('../dao/MySQLPool');

class CoinUpdateLogDao {
    constructor() {
    }

    /**
     *
     * @param {{uid: String, coin: Number, remark: String, curCoin: Number, type: String, operator: String}} coinUpdateLog
     * @returns {Promise<*>}
     */
    async save(coinUpdateLog) {
        let sql = 'insert into coin_update_log (uid, coin, remark, cur_coin, type, operator, create_time, update_time)' +
            '                           values (?,   ?,    ?,      ?,        ?,    ?,        now(),       now())';
        let args = [coinUpdateLog.uid, coinUpdateLog.coin, coinUpdateLog.remark, coinUpdateLog.curCoin, coinUpdateLog.type, coinUpdateLog.operator];
        let res = await mysqlPool.query(sql, args);
        if (res) {
            return res.insertId;
        }

        return 0;
    }
}

let coinUpdateLogDao = new CoinUpdateLogDao();
module.exports = coinUpdateLogDao;